package com.bringway.framework.util.ftp;

import java.io.IOException;
import org.apache.commons.lang.StringUtils;
import org.omg.CORBA.portable.ApplicationException;
import com.bringway.framework.exception.ServiceException;
import com.bringway.global.constant.FMConstant;

public class FtpConfig {
	
	private String host;
	private int port;
	private String root;
	private String username;
	private String password;

	
	public static boolean loaded = false;

	public String getHost() {
		return host;
	}

	public void setHost(String hose) {
		this.host = hose;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public int getPort() {
		return port;
	}

	public void setPort(int port) {
		this.port = port;
	}

	public String getRoot() {
		return root;
	}

	public void setRoot(String root) {
		this.root = root;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	/**
	 * 加载Ftp服务器信息。
	 * @throws ApplicationException 
	 * 
	 * @throws IOException
	 */
	public void load() throws ServiceException {
		String ftpHost = FMConstant.getFtpHost();
		String ftpPort = FMConstant.getFtpPort();
		String ftpUsername = FMConstant.getFtpUserName();
		String ftpPassword = FMConstant.getFtpPassWord();
		String ftpRoot = FMConstant.getFtpRoot();

		if (StringUtils.isNotEmpty(ftpHost)) {
			host = ftpHost;
		}
		if (StringUtils.isNotEmpty(ftpPort)) {
			port = Integer.parseInt(ftpPort);
		}

		if (StringUtils.isNotEmpty(ftpUsername)) {
			username = ftpUsername;
		}

		if (StringUtils.isNotEmpty(ftpPassword)) {
			password = ftpPassword;
		}

		if (StringUtils.isNotEmpty(ftpRoot)) {
			root = ftpRoot;
		}
		loaded = true;
	}
}
